import groovy.lang.Binding;
import groovy.lang.GroovyShell;

import java.io.IOException;

/**
 * 作者: LDL
 * 功能说明:
 * 创建日期: 2015/8/19 15:03
 */
public class GroovyTest {

    public static void main(String[] args) throws IOException, IllegalAccessException, InstantiationException {
        /*ClassLoader parent = ClassLoader.getSystemClassLoader();

        GroovyClassLoader loader = new GroovyClassLoader(parent);

        Class groovyClass = loader.parseClass(new File("D:\\GroovyDemo.groovy"));

        GroovyObject groovyObject = (GroovyObject)groovyClass.newInstance();

        Object[] param = {123,321};

        int res = (int) groovyObject.invokeMethod("add", param);

        System.out.println("res="+res);*/
        Binding binding = new Binding();

        binding.setVariable("x", 5);
        binding.setVariable("y", 10);

        GroovyShell gs = new GroovyShell(binding);

        Object value = gs.evaluate("import com.google.common.collect.Lists;List<String> s = Lists.newArrayList();x;y;z=x+y;return z;");//执行groovyshell脚本

        System.out.println(value);

    }
}
